﻿@page "/fetchdata"

@using MaBlaApp.Data
@inject TodoService MyTodoService

<ul class="list-group">
    <li class="list-group-item list-group-item-primary d-flex justify-content-between">
        <strong class="align-self-center">任务列表</strong>
        <a href="fetchdata/todoitem/create" class="btn btn-primary btn-sm">新建任务</a>
    </li>
</ul>

@if (todoItems == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <div class="list-group" style="overflow:auto">
        @foreach (var todoItem in todoItems)
        {
            string url = $"fetchdata/todoitem/details/{todoItem.Id}";
            <a href=@url class="list-group-item list-group-item-action d-flex justify-content-between mb-1">
                <strong>@todoItem.Title</strong>
                <small>@todoItem.Description</small>
            </a>
        }
    </div>
}

@code {
    private List<TodoItem> todoItems;

    protected override void OnInitialized()
    {
        todoItems = MyTodoService.TodoItems;
    }

}
